/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.mailbox.Contact;
/*    */ import com.zimbra.cs.mailbox.MailServiceException;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.formatter.ContactCSV;
/*    */ import com.zimbra.cs.service.formatter.ContactCSV.ParseException;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.soap.JaxbUtil;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.mail.message.ExportContactsRequest;
/*    */ import com.zimbra.soap.mail.message.ExportContactsResponse;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public final class ExportContacts
/*    */   extends MailDocumentHandler
/*    */ {
/* 43 */   private static final String[] TARGET_FOLDER_PATH = { "l" };
/*    */   
/*    */ 
/*    */   protected String[] getProxiedIdPath(Element request)
/*    */   {
/* 48 */     return TARGET_FOLDER_PATH;
/*    */   }
/*    */   
/*    */   protected boolean checkMountpointProxy(Element request)
/*    */   {
/* 53 */     return true;
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 59 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 60 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 61 */     OperationContext octxt = getOperationContext(zsc, context);
/*    */     
/* 63 */     ExportContactsRequest req = (ExportContactsRequest)JaxbUtil.elementToJaxb(request);
/* 64 */     String folder = req.getFolderId();
/* 65 */     ItemId iidFolder = folder == null ? null : new ItemId(folder, zsc);
/*    */     
/* 67 */     String ct = req.getContentType();
/* 68 */     if (ct == null) {
/* 69 */       throw ServiceException.INVALID_REQUEST("content type missing", null);
/*    */     }
/* 71 */     if (!ct.equals("csv")) {
/* 72 */       throw ServiceException.INVALID_REQUEST("unsupported content type: " + ct, null);
/*    */     }
/*    */     
/* 75 */     String format = req.getCsvFormat();
/* 76 */     String locale = req.getCsvLocale();
/* 77 */     String separator = req.getCsvDelimiter();
/* 78 */     Character sepChar = null;
/* 79 */     if ((separator != null) && (separator.length() > 0)) {
/* 80 */       sepChar = Character.valueOf(separator.charAt(0));
/*    */     }
/* 82 */     List<Contact> contacts = mbox.getContactList(octxt, iidFolder != null ? iidFolder.getId() : -1);
/*    */     
/*    */ 
/* 85 */     StringBuilder sb = new StringBuilder();
/* 86 */     if (contacts == null) {
/* 87 */       contacts = new ArrayList();
/*    */     }
/*    */     try {
/* 90 */       ContactCSV contactCSV = new ContactCSV(mbox, octxt);
/* 91 */       contactCSV.toCSV(format, locale, sepChar, contacts.iterator(), sb);
/*    */     } catch (ContactCSV.ParseException e) {
/* 93 */       throw MailServiceException.UNABLE_TO_EXPORT_CONTACTS(e.getMessage(), e);
/*    */     }
/*    */     
/*    */ 
/* 97 */     ExportContactsResponse resp = new ExportContactsResponse(sb.toString());
/* 98 */     return zsc.jaxbToElement(resp);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/ExportContacts.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */